Skip to content

perf: Replace git subprocesses with libgit2 and skip unnecessary summary work#11938

Merged
anthonyshew merged 2 commits intomainfrom
faster-and-faster
Feb 20, 2026
Merged

perf: Replace git subprocesses with libgit2 and skip unnecessary summary work#11938
anthonyshew merged 2 commits intomainfrom
faster-and-faster

Conversation

@anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Feb 20, 2026

Summary

  • Replace the three hottest git subprocess calls (WorktreeInfo::detect, git ls-tree, git status) with in-process libgit2 equivalents, eliminating fork+exec overhead
  • Skip TaskSummary construction and SCMState::get (2 git subprocesses) when neither --dry nor --summarize is set
  • Use sorted Vec with partition_point instead of BTreeMap for ls-tree results (better cache locality)
  • Return BTreeMap directly from HashTrackerInfo::expanded_inputs trait, eliminating an intermediate HashMap clone

Small repo (~6 packages):

Run main this branch speedup
1 798.1ms ± 28.1ms 656.0ms ± 65.4ms 1.17x ± 0.27
2 790.1ms ± 36.4ms 656.0ms ± 65.4ms 1.20x ± 0.13

Medium repo (~120 packages):

Run main this branch speedup
1 1.196s ± 0.161s 1.132s ± 0.086s 1.06x ± 0.16
2 1.106s ± 0.077s 1.095s ± 0.047s 1.01x ± 0.08

Large repo (~1000 packages):

Run main this branch speedup
1 1.697s ± 0.100s 1.754s ± 0.131s 1.03x ± 0.10
2 1.710s ± 0.084s 1.794s ± 0.206s 1.05x ± 0.13

This is a small fixed-cost for all repos, so we don't expect to be able to see these improvements as easily the larger the repo gets.

Measured with hyperfine comparing main (Benchmark 2) vs this branch (Benchmark 1), --warmup 5, 10 runs each. All runs use --skip-infer --dry.

Note: the --dry flag means the lazy summary optimization doesn't apply in these benchmarks. Real turbo run invocations (without --dry or --summarize) will see additional savings from skipping TaskSummary construction and SCMState::get.

@anthonyshew anthonyshew requested a review from a team as a code owner February 20, 2026 20:01
@anthonyshew anthonyshew requested review from tknickman and removed request for a team February 20, 2026 20:01
@vercel
Copy link
Contributor

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples-basic-web Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-designsystem-docs Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-gatsby-web Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-kitchensink-blog Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-nonmonorepo Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-svelte-web Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-tailwind-web Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
examples-vite-web Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
turbo-site Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
turborepo-agents Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm
turborepo-test-coverage Ready Ready Preview, Comment, Open in v0 Feb 20, 2026 9:28pm

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2026

Coverage Report

Metric Coverage
Lines 75.06%
Functions 46.71%
Branches 0.00%

View full report

@anthonyshew anthonyshew changed the title perf: Upgrade hot-path dependencies for ~1% improvement perf: Replace git subprocesses with libgit2 and skip unnecessary summary work Feb 20, 2026
@anthonyshew anthonyshew changed the title perf: Replace git subprocesses with libgit2 and skip unnecessary summary work perf: Replace git subprocesses with libgit2 and skip unnecessary summary work Feb 20, 2026
Eliminate fork+exec overhead for the three hottest git subprocess calls
in turbo run startup: WorktreeInfo::detect, git ls-tree, and git status.
Replace with in-process libgit2 equivalents (Repository::discover,
tree.walk, repo.statuses).

Also skip expensive TaskSummary construction and SCMState::get when
neither --dry nor --summarize is set, and use sorted Vec instead of
BTreeMap for ls-tree results for better cache locality.
@anthonyshew anthonyshew merged commit 58e3c00 into main Feb 20, 2026
103 checks passed
@anthonyshew anthonyshew deleted the faster-and-faster branch February 20, 2026 21:43
github-actions bot added a commit that referenced this pull request Feb 20, 2026
## Release v2.8.11-canary.15

Versioned docs: https://v2-8-11-canary-15.turborepo.dev

### Changes

- release(turborepo): 2.8.11-canary.14 (#11939) (`59866f5`)
- perf: Replace git subprocesses with `libgit2` and skip unnecessary
summary work (#11938) (`58e3c00`)

---------

Co-authored-by: Turbobot <turbobot@vercel.com>
anthonyshew added a commit that referenced this pull request Feb 20, 2026
…ses (#11942)

## Summary

Follow-up to #11938. Targets the per-package hashing hot path that
dominates at scale, plus eliminates the last two git subprocesses from
`--dry` runs.

### Small repo (~6 packages)

| | Mean | Range |
|---|---|---|
| **This PR** | 571.2ms ± 46.7ms | 515.6ms - 651.7ms |
| **main** | 587.4ms ± 45.1ms | 524.9ms - 676.3ms |
| | **1.03 ± 0.12x faster** | |

### Medium repo (~120 packages)

| | Mean | Range |
|---|---|---|
| **This PR** | 1.096s ± 0.095s | 1.015s - 1.280s |
| **main** | 1.119s ± 0.072s | 1.042s - 1.259s |
| | **1.02 ± 0.11x faster** | |

### Large repo (~1000 packages)

| | Mean | Range |
|---|---|---|
| **This PR** | 1.729s ± 0.151s | 1.548s - 1.969s |
| **main** | 1.833s ± 0.181s | 1.583s - 2.099s |
| | **1.06 ± 0.14x faster** | |

The small repo results best isolate the fixed-cost improvements (git2
for branch/SHA, reduced allocation overhead) since per-package work is
minimal. At larger scales, the improvements are present but within noise
because wall-clock time is already well-parallelized across rayon
threads.

## Benchmarks

All benchmarks: `turbo run <task> --skip-infer --dry`, 5 warmup + 10
measured runs, release build.

## Changes

- **FileHashes: HashMap to sorted Vec** — `FileHashes` inner type
changed from `HashMap` to pre-sorted `Vec`. Eliminates HashMap
construction (hashing, bucket allocation, rehashing) in the per-package
hashing pipeline and removes redundant re-sorting in Cap'n Proto
serialization. The sort happens once at the construction boundary;
downstream consumers (`expanded_inputs`, `.hash()`) get pre-sorted data
for free.

- **Status entry binary search** — `get_package_hashes` now uses
`partition_point` on pre-sorted status entries instead of a linear scan.
Reduces per-package status lookup from O(dirty_files) to
O(log(dirty_files) + matched). Also adds `with_capacity` to the
per-package HashMap to avoid rehashing.

- **git2 for branch/SHA** — `get_current_branch` and `get_current_sha`
(called by `SCMState::get` in `to_summary`) now use `git2::Repository`
instead of forking `git branch --show-current` and `git rev-parse HEAD`.
Gated behind `#[cfg(feature = "git2")]` with subprocess fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant